from processtiles import main
import sys


def run_gdal2tiles(input_file: str, output_folder: str, zoom_levels: str):
    """构造与命令行相同的参数进行切片，不改变原切片代码
       默认--xyz格式瓦片,并只保留leaflet.html,可根据gdal2tiles自主调整 
    Args:
        input_file (str): geotif文件全路径
        output_folder (str): 瓦片存储文件夹
        zoom_levels (str): 切片级别
    """
    # 构造与命令行相同的参数
    
    argv = ['gdal2tiles.py', '--zoom={}'.format(zoom_levels), '--xyz', '--webviewer=leaflet',input_file, output_folder]
    sys.exit(main(argv))



if __name__ == "__main__":
    input_file_path = r'./RD0100_DataCloud_K51D005005_2023H1_4FF_COG.tif'
    output_dir_path = r'./tiles_save'
    zoom_levels = '2-3'

    # 运行
    run_gdal2tiles(input_file_path, output_dir_path, zoom_levels)